<?php
namespace V1;
class ResourceList extends \ResourceClass {

  public function get(array $req, array $post, &$result) {
    $result = array();
    $fileList = scandir('./service');
    foreach ($fileList as $file) {
      if ($file == '.' || $file == '..' || $file == 'ResourceClass.php' || $file == 'ResourceList.php') {
        continue;
      }
      $tmpArray = explode('.', $file);
      if (count($tmpArray) != 2) {
        continue;
      }
      $resource = $tmpArray[0];
      $ext = $tmpArray[1];
      if (strtolower($ext) != 'php') {
        continue;
      }
      if (class_exists($resource)) {
        $obj = new $resource();
        $tmp = array();
        $tmp['name'] = $resource;
        $tmp['is_active'] = $obj->isActive;
        $tmp['remark'] = $obj->remark;
        $tmp['actionList'] = $this->getDeclaredMethods($resource);
        $result[] = $tmp;
      }
    }
    return '';
  }

  private function getDeclaredMethods($className) {
    $reflector = new ReflectionClass($className);
    $methodNames = array();
    $lowerClassName = strtolower($className);
    foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
        if (strtolower($method->class) == $lowerClassName) {
            $methodNames[] = $method->name;
        }
    }
    return $methodNames;
  }
}
?>